<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // var hobby1 = ['打球', '吃饭']
      // var hobby2 = []
      // for (var i = 0; i < hobby1.length; i++) {
      //   hobby2.push(hobby1[i])
      // }
      // console.log(hobby1)
      // console.log(hobby2)
      // console.log(hobby1 === hobby2) // false

      //   封装函数：实现对数组的深拷贝（一层）
      function copyDeep(arr) {
        var result = []
        for (var i = 0; i < arr.length; i++) {
          result.push(arr[i])
        }
        return result
      }

      var hobby1 = ['打球', '吃饭']
      var hobby2 = copyDeep(hobby1)
      console.log(hobby1)
      console.log(hobby2)
      console.log(hobby1 === hobby2) // false
    </script>
  </body>
</html>
